<template>
	<view>
		<navBar title="申请售后" backJudge></navBar>
		<view class=""></view>
		<view class="feedbackBox">
			<view class="no">订单号:{{form.orderNo}}</view>
			<view class="title">申请售后原因</view>
			<view class="tagsBox">
				<view class="tag" v-for="(item,index) in tags" :key="index" :class="item.id === form.title?'act':''"
					@click="form.title = item.id">{{item.name}}</view>
			</view>
			<view class="content">
				<uni-easyinput type="textarea" placeholder="原因" v-model="form.content"></uni-easyinput>
			</view>
			<uni-easyinput v-model="form.phone" placeholder="联系方式"></uni-easyinput>
			<view class="title" style="margin-top: 10px;">截图或者图片（选填）</view>
			<view class="imgBox">
				<view @click="addImg" class="imgUp">
					<uni-icons size="25" type="camera-filled"></uni-icons>
				</view>
				<image class="img" mode="aspectFill" v-for="(item,index) in imgList" :key="index" :src="item"></image>
			</view>
			<view class="buttonBox" @click="feedback">提交申请</view>
		</view>
		<view class="listBox" v-if="actIndex === 1 ">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="title">{{item.title.name}}</view>
				<view class="imgBox">
					<image class="img" v-for="(itemImg,indexImg) in JSON.parse(item.image)"  :key="indexImg" mode="aspectFill" :src="itemImg"></image>
				</view>
				<view class="content">{{item.content}}</view>
				<view class="time">{{item.createTime}}</view>
			</view>
		</view>
	</view>
</template>

<script>
import { refund,dict,upImg } from '@/utils/API.js'
import navBar from '../../components/navbars/navbars.vue'
	export default {
		data() {
			return {
				tags: ['服务态度', '质量问题', '其它'],
				list: [],
				form: {
					image: '',
					phone: '',
					orderNo:'',
					content:'',
					title:0
				},
				imgList:[]
			}
		},
		components:{
			navBar
		},
		onLoad(e) {
			this.form.orderNo = e.orderNo
			this.getDict()
		},
		methods: {
			async getDict(){
				const res = await dict('sold_type')
				if(res.code==200){
					this.tags = res.data.map(item=>{
						return {
							name:item.dictLabel,
							id:item.dictCode
						}
					})
					this.title = this.tags[0].id
				}
			},
			async upImg(data){
				const res = await upImg(data)
				if(res.code==200){
					this.imgList.push(res.data.url)
				}
			},
			addImg() {
				var that = this
				uni.chooseImage({
					count: 1,
					success: (res) => {
						var data = {
							file: res.tempFilePaths[0]
						}
						that.upImg(data)
					}
				})
			},
			async feedback(){
				if(this.form.phone==''){
					uni.showToast({
						title:'请填写手机号',
						icon:'none'
					})
					return
				}
				var data = this.form
				data.image = this.imgList
				const res = await refund(data)
				if(res.c0de==200){
					uni.showToast({
						title:'反馈成功',
						icon:'none'
					})
					setTimeout(()=>{
						uni.navigateBack()
					},1500)
				}else{
					uni.showToast({
						title:err.message,
						icon:'none'
					})
				}
				
			},
		}
	}
</script>

<style lang="scss" scoped>

	
	.imgBox {
		display: flex;
		flex-wrap: wrap;
	
		.imgUp {
			background-color: $backGrey;
			width: calc((100vw - 80px) / 4);
			height: calc((100vw - 80px) / 4);
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 5px;
			margin: 5px;
		}
	
		.img {
			width: calc((100vw - 80px) / 4);
			height: calc((100vw - 80px) / 4);
			margin: 5px;
		}
	}
	
	.feedbackBox {
		padding: 20px;
		background-color: white;
		margin: 10px 0px;

		.no{
			font-size: 14px;
			margin-bottom: 10px;
		}

		.title{
			font-size: 14px;
			font-weight: bold;
		}

		.imgs {
			display: flex;
			align-items: center;
			margin-top: 10px;

			.img {
				height: 50px;
				width: 50px;
			}
		}

		.content {
			padding: 10px 0;
		}

		.tagsBox {
			display: flex;
			flex-wrap: wrap;
			border-bottom: 1px solid $shollowGrey;
			padding-bottom: 10px;

			.tag {
				padding: 3px 5px;
				font-size: 14px;
				border: 1px solid rgba(0, 0, 0, 0.1608);
				border-radius: 5px;
				margin-top: 10px;
				margin-right: 10px;
			}

			.act {
				border: 1px solid $blue;
			}
		}
	}

	.tabBar {
		display: flex;
		align-items: center;
		background-color: white;
		padding: 0px 20px;

		.tab {
			padding: 20px 0px;
			width: 50%;
			font-weight: bold;
			box-sizing: border-box;
			text-align: center;
		}

		.actTab {
			color: $blue;
			border-bottom: 2px solid $blue;
		}
	}

	.buttonBox {
		position: fixed;
		bottom: 0px;
		left: 0px;
		background-color: $blue;
		color: white;
		padding: 10px;
		width: calc(100vw - 60px);
		margin: 20px;
		text-align: center;
		border-radius: 20px;
	}



	body {
		background-color: $MainBackColor;
	}
</style>